function disabledComponente(id){
	document.getElementById(id).disabled=true;
}
function enabledComponente(id){
	document.getElementById(id).disabled=false;
}
function ocultarComponente(id){
	document.getElementById(id).style.display='none';
}
function mostrarComponente(id){
	document.getElementById(id).style.display='block';	
}

function simularBoton(idForm, boton){
	var button = document.getElementById(idForm + ':' + boton);
	button.click();
}

function simularBoton(idButton){
	var button = document.getElementById(idButton);	
	button.click();
}

function muestraCapa(idCapa,idComponente){
	
	var capa=document.getElementById(idCapa);
	var ocultado=document.getElementById(idComponente);		
	capa.style.width  = ocultado.style.width;
	capa.style.height = ocultado.style.height;			
	capa.style.display='block';
	
	
}

function ocultaCapa(idCapa){	
	
	document.getElementById(idCapa).style.display='none';
	
}

function seleccionaTodos(componente, idHidden,indicadorFooter){
    var objHidden = document.getElementById(idHidden);
    var valorHidden='';
	if(componente.checked){
		var temp2 = jQuery(componente).parents('thead').get(0);
		
		if(indicadorFooter == null){
			temp2 = jQuery(temp2).next().next();
		}else{
			temp2 = jQuery(temp2).next();
		}
		
		var filas = jQuery(temp2).children();	
		filas.addClass('active-row');
		var inputsCheckBox = filas.find('input:checkbox');
		inputsCheckBox.attr('checked','checked');
		
		valorHidden = '';
		for(k=0;k<inputsCheckBox.length;k++){
			var elemento = inputsCheckBox.get(k);			
			if(k == inputsCheckBox.length-1){
				valorHidden = valorHidden + document.getElementById(elemento.id+'_Id').value ; 
			}else{
				valorHidden = valorHidden + document.getElementById(elemento.id+'_Id').value +',' ;
			}
		}
	
		
	}else{
		valorHidden = '';
		var temp2 = jQuery(componente).parents('thead').get(0);
		if(indicadorFooter == null){
			temp2 = jQuery(temp2).next().next();
		}else{
			temp2 = jQuery(temp2).next();
		}
		var filas = jQuery(temp2).children();
		filas.removeClass("active-row");
		filas.find('input:checkbox').removeAttr('checked');
	}
	objHidden.value=valorHidden;
	
}

function seleccionCheckBox(componente,idHidden){
    var valorHidden = document.getElementById(idHidden).value;
    var valorSeleccionado=document.getElementById(componente.id+'_Id').value;

    var arreglo;
    if(valorHidden!=''){
    	arreglo = valorHidden.split(',');
    }else{
    	arreglo =new Array();
    }
    
	if(componente.checked){
		var row = jQuery(componente).parents('tr').get(0);			
		jQuery(row).addClass('active-row');		
		arreglo.push(valorSeleccionado);	
	}else{
		
		
		var row = jQuery(componente).parents('tr').get(0);		
		jQuery(row).removeClass('active-row');
		
		var checkBoxTodos = jQuery(jQuery(componente).parents('tbody').get(0)).prev().prev();		
		jQuery(checkBoxTodos).find('input:checkbox').removeAttr('checked');
		
		for(k=0;k<arreglo.length  ;k++){
			if(arreglo[k]==valorSeleccionado){
				arreglo[k]= arreglo[arreglo.length-1];
				break;
			}
		}
		arreglo.pop();
	}
	if(arreglo.length>0){
		document.getElementById(idHidden).value = arreglo.join(',');
	}else{
		document.getElementById(idHidden).value='';
	}
	//alert(document.getElementById(idHidden).value);
	
}

/********************************************************************
*Valida el ingreso de caracteres a un control de texto
*
*********************************************************************/
var DEC_PATTERN=/\d{0,}\.?\d{0,2}/;
var SDEC_PATTERN=/\-?\d{0,}\.?\d{0,2}/;
var DBL_PATTERN=/\d{0,}\.?\d{0,}/;
var INT_PATTERN=/\d{0,}/;
var SINT_PATTERN=/\-?\d{0,}/;
var FEC_PATTERN=/\d{0,2}\/?\d{0,2}\/?\d{0,4}/; 
var MES_ANIO=/\d{0,2}\/?\d{0,4}/; 
var ANIO_MES=/\d{0,4}\/?\d{0,2}/; 
var TEL_PATTERN=/(\d{0,}\-*)*/; 
var ALFA_PATTERN=/[\w\s\.\,\xB0\/\-\xD1\xF1]*/;
var ALFASE_PATTERN=/[\w\.\,\xB0\/\-\xD1\xF1]*/;
var LETTER_PATTERN=/[A-Za-z\s]*/; 
var TIME_PATTERN=/\d{0,2}:?\d{0,2}/; ///^([01]?[0-9]|[2][0-3])(:[0-5][0-9])?$/; 
var DATE_TIME_PATTERN=/^(\d{0,2})\/?(\d{0,2})\/?(\d{0,4})\s?(\d{0,2})?:?(\d{0,2})?$/; 
var MAIL_PATTERN=/^[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+.)+([a-zA-Z]{2,4})$/;
var IDVAR_PATTERN=/[A-Za-z][A-Za-z0-9_]*/; //identificador de variable
var WHITE_PATTERN = /\s+/;
 

function validKey(format,evento){
	
	if (!evento) var evento = window.event;
	
	if (evento.target) var targ = evento.target;
	else if (evento.srcElement) var targ = evento.srcElement;

	if (evento.keyCode) code = evento.keyCode;
	else if (evento.which) code = evento.which;
	
	if(code ==8 ||code ==9 || code ==37 || code ==39 || code ==46 )
		return true;
	
	var text = targ.value + String.fromCharCode(code);
	
	var arr = format.exec(text);
	
	return (arr!=null && text==arr[0]);
}

function validKeyAlt(format){	
	el = event.srcElement;	
	str1 = el.value;
	rango1 = document.selection.createRange().duplicate();
	while(rango1.expand("character"));

	var text = str1.substr(0,str1.length-rango1.text.length)
		+ String.fromCharCode(event.keyCode) + rango1.text ;
	
	var arr = format.exec(text);
	
	return (arr!=null && text==arr[0]);
}



